import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

export default new Router({
  routes: [
    // 首页
    {
      path: '/',
      name: 'home',
      component: () => import('@/components/home.vue'),
      // 是否显示
      meta: {
        keppAlive: false
      }
    },
    // 登录
    {
      path: '/login',
      name: 'login',
      component: () => import('@/components/login.vue'),
    },
    // 注册
    {
      path: '/register',
      name: 'register',
      component: () => import('@/components/register.vue'),
    },
    // 视频展示
    {
      path: '/video',
      name: 'video',
      component: () => import('@/components/video.vue'),
    },
    //个人中心 
    {
      path: '/personalcenter',
      name: 'personalcenter',
      component: () => import('@/components/PersonalCenter.vue'),
    },
    // 使用说明页面
    {
      path: '/instructions',
      name: 'instructions',
      component: () => import('@/components/instructions.vue'),
    },
    // 空白页面
    {
      path: '/emptyPage',
      name: 'emptyPage',
      component: () => import('@/components/emptyPage.vue'),
    },
    // 问卷调查
    {
      path: '/questionnaire',
      name: 'questionnaire',
      // 路由懒加载
      component: () => import('@/components/questionnaire/questionnaire.vue'),
      // 问卷调查下面的子路由
      children: [{
          // 编辑问卷
          path: "edit",
          component: () => import('@/components/questionnaire/children/edit.vue'),
        }, {
          // 发布问卷
          path: "release",
          component: () => import('@/components/questionnaire/children/release.vue'),
        }, {
          // 设置问卷
          path: "setup",
          component: () => import('@/components/questionnaire/children/setup.vue'),
        }, {
          // 答案填写
          path: "fillin",
          component: () => import('@/components/questionnaire/children/fillin.vue'),
        }, {
          // 复制链接给别人填写
          path: "answernaire",
          component: () => import('@/components/questionnaire/children/answernaire.vue'),
        }, {
          // 数据分析页面
          path: "analysis",
          component: () => import('@/components/questionnaire/children/analysis.vue'),
          children: [{
              //单选 饼状图
              path: "piechart",
              component: () => import('@/components/questionnaire/echart/piechart.vue')
            }, {
              //单选 柱状图
              path: "columnchart",
              component: () => import('@/components/questionnaire/echart/columnchart.vue')
            }, {
              // 多项 词云图
              path: "wordcloudchart",
              component: () => import('@/components/questionnaire/echart/wordcloudchart.vue')
            }, {
              // 多选 雷达图
              path: "radarchart",
              component: () => import('@/components/questionnaire/echart/radarchart.vue')
            }, {
              // 整体分析 折线图
              path: "brokenline",
              component: () => import('@/components/questionnaire/echart/brokenlinechart.vue')
            }, {
              // 整体分析 中国地图
              path: "map",
              component: () => import('@/components/questionnaire/echart/mapchart.vue')
            }

          ]
        }

      ]
    },
  ]
})
// const router = new VueRouter({
//   router
// })
// // 注册导航守卫
// router.beforeEach((to, from, next) => {
//   // to and from are both route objects. must call `next`.
//   // 需要判断的页面   个人中心的判断令牌
//   if (to.path.indexOf('/personalcenter') == 0) {
//     // 判断token是否存在
//     if (window.localStorage.getItem('token') != null) {
//       next()
//     } else {
//       Vue.prototype.$message.error('请登录...')
//       // 打回登录页面
//       router.push('/login')
//       // 或者使用 next('/login')
//       // next('/login')
//     }
//   } else {
//     // 不需要判断的页面
//     next()
//   }
// })
